package com.example.controller;

import com.example.data.attendance.Attendance;
import com.example.data.attendance.AttendanceVO;
import com.example.service.attendance.AttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class AttendanceController {
    private AttendanceService attendanceServiceImpl;
    @Autowired
    public AttendanceController(AttendanceService attendanceServiceImpl){
        this.attendanceServiceImpl = attendanceServiceImpl;
    }
    @GetMapping("/attendance")
    public List<Attendance> getAllAttendance(){
        return attendanceServiceImpl.getAllAttendance();
    }
    @GetMapping("/attendance/id")
    public List<Attendance> getAttendanceByID(@RequestParam(value = "empID", required = false) Long empID,
                                                                        @RequestParam(value = "attendanceID", required = false) Long attendanceID){
        return attendanceServiceImpl.getAttendanceByID(empID, attendanceID);
    }
    @PostMapping("/attendance")
    public List<Attendance> addAttendance(@RequestBody Attendance attendance){
        return attendanceServiceImpl.addAttendance(AttendanceVO.convert(attendance));
    }
    @DeleteMapping("/attendance/id")
    public void deleteAttendance(@RequestParam long attendanceID){
       attendanceServiceImpl.deleteAttendance(attendanceID);
    }
}
